//用户信息数据
function createUserList() {
    return [
        {
            userId: 1,
            avatar:
                'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'admin',
            password: '111111',
            desc: '平台管理员',
            roles: ['平台管理员'],
            buttons: ['cuser.detail'],
            routes: ['home'],
            token: 'Admin Token',
        },
        {
            userId: 2,
            avatar:
                'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'system',
            password: '111111',
            desc: '系统管理员',
            roles: ['系统管理员'],
            buttons: ['cuser.detail', 'cuser.user'],
            routes: ['home'],
            token: 'System Token',
        },
    ]
}
//轮播图数据
function carouselData(){
    return[
        {
            id: "101",
            imgUrl: "/images/banner.png"
        },
        {
            id: "201",
            imgUrl: "/images/banner1.png"
        },
        {
            id: "301",
            imgUrl: "/images/banner2.png"
        },
        {
            id: "401",
            imgUrl: "/images/banner3.png"
        }
    ]
}
//获取商品数据
function productData(){
    return[
        {
            id:"110",
            image:"./images/amx.webp",
            name:'伊利安慕希AMX长白山蓝莓味减糖酸奶230g10瓶整箱礼盒产地直采',
            price:95,
            productDetail:[
                {    
                detailID:'1220',
                imgs:'./images/amx1.jpg' ,
                   
                },
                {    
                 detailID:'1320',
                 imgs:'./images/amx2.webp' ,
                    
                 },
                 {    
                     detailID:'1420',
                     imgs:'./images/amx3.jpg' ,
                        
                     }
            ]
        },
        {
            id:"1109",
            image:"./images/amx_.webp",
            name:'伊利安慕希AMX丹东草莓味酸奶230g10瓶/整箱礼盒学生营养早餐',
            price:107,
            productDetail:[
                {    
                detailID:'12200',
                imgs:'./images/amx1.jpg' ,
                   
                },
                {    
                 detailID:'1320',
                 imgs:'./images/amx2.webp' ,
                    
                 },
                 {    
                     detailID:'120',
                     imgs:'./images/amx3.jpg' ,
                        
                     }
            ]
        },
        {
            id:"101",
            image:"./images/1.jpg",
            name:'旺仔',
            price:4,
            productDetail:[
                {     
                detailID:'2121',
                    imgs:'./images/wz01.webp'  
                },
                {     
                detailID:'3121',
                    imgs:'./images/wz02.webp'  
                },
                {     
                    detailID:'4121',
                        imgs:'./images/wz03.webp'  
                    }
            ]
        },
        {
            id:"111",
            image:"./images/3.jpg",
            name:'老酸奶',
            price:15,
            productDetail:[
                {
                    
                detailID:'1123',
                    imgs:'./images/1006_03.jpg' 
                },
                {     
                    detailID:'4e21',
                        imgs:'./images/wz03.webp'  
                    }
            ]
        },
        {
            id:"112",
            image:"./images/1002_01.jpg",
            name:'女生运动内衣',
            price:150,
            productDetail:[
                {
                detailID:'1124',
                  imgs:'../images/1006_03.jpg' ,
                  context:'质量good' 
                },
                {
                    imgs:'./images/1006_01.jpg',  
                    detailID:'1125',
                },
                {
                    imgs:'./images/1002_01.jpg' , 
                    detailID:'1126',
                },


            ]
        },
        {
            id:"113",
            image:"./images/4.jpg",
            name:'纯奶',
            price:4,
            productDetail:[
                {
                    detailID:'14428',
                    imgs:"./images/cn01.webp", 
                },
                {
                    detailID:'14528',
                    imgs:"./images/cn02.jpg", 
                },
                {
                    detailID:'14628',
                    imgs:"./images/cn03.webp", 
                }
            ]
        },
        {
            id:"114",
            image:"./images/5.jpg",
            name:'优酸乳',
            price:2.5,
            productDetail:[
                {
                    detailID:'1127',  
                    imgs:"./images/u1.webp",
                },
                {
                    detailID:'1138',  
                    imgs:"./images/u2.webp",
                },
                {
                    detailID:'1148',  
                    imgs:"./images/u3.webp",
                }
            ]
        }
    ]
}
export default [
    // 用户登录接口
    {
        url: '/api/user/login',//请求地址
        method: 'post',//请求方式
        response: ({ body }) => {
            //获取请求体携带过来的用户名与密码
            const { username, password } = body;
            //调用获取用户信息函数,用于判断是否有此用户
            const checkUser = createUserList().find(
                (item) => item.username === username && item.password === password,
            )
            //没有用户返回失败信息
            if (!checkUser) {
                return { code: 201, data: { message: '账号或者密码不正确' } }
            }
            //如果有返回成功信息
            const { token } = checkUser
            return { code: 200, data: { token } }
        },
    },
    // 获取用户信息
    {
        url: '/api/user/info',
        method: 'get',
        response: (request) => {
            //获取请求头携带token
            const token = request.headers.token;
            //查看用户信息是否包含有次token用户
            const checkUser = createUserList().find((item) => item.token === token)
            //没有返回失败的信息
            if (!checkUser) {
                return { code: 201, data: { message: '获取用户信息失败' } }
            }
            //如果有返回成功信息
            return { code: 200, data: {checkUser} }
        },
    },
    //轮播图接口
    {
        url: '/api/user/banner', // 请求地址
        method: 'get', // 请求方式
        response: () => {
            return { code: 200, data: carouselData };
        }
    },
    //商品数据接口
    {
        url: '/api/user/product', // 请求地址
        method: 'get', // 请求方式
        response: () => {
            return { code: 200, data: productData};
        } 
    }
]